﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.IO;

namespace FigureDraw.Graphic
{
    class GDIPlusPNGGraphic : CommonGraphic
    {
        string filename;
        Image image;
        Graphics g;
        Pen p;

        public GDIPlusPNGGraphic(string filename)
        {
            this.filename = filename;

            if (File.Exists(filename))
            {
                FileStream fs = File.Open(filename, FileMode.Open);
                image = Image.FromStream(fs);
                fs.Close();
            }
            else
            {
                Bitmap bm = new Bitmap(800, 600);
                image = (Image)bm;
            }

            g = Graphics.FromImage(image);
            p = new Pen(Color.Black);
        }

        override public void DrawLine(double x1, double y1, double x2, double y2)
        {
            g.DrawLine(p, (float)x1, (float)y1, (float)x2, (float)y2);
            image.Save(filename);
        }

        override public void DrawRectangle(double x, double y, double width, double height)
        {
            g.DrawRectangle(p, (float)x, (float)y, (float)width, (float)height);
            image.Save(filename);
        }

        override public void DrawEllipse(double x, double y, double width, double height)
        {
            g.DrawEllipse(p, (float)x, (float)y, (float)width, (float)height);
            image.Save(filename);
        }


        public override void DrawPicture(List<MyShape> shapes)
        {
            base.DrawPicture(shapes);
            image.Save(filename);
        }

        public override void DrawText(string text, double size, double x, double y)
        {
            throw new NotImplementedException();
        }

        public override void DrawArc(double x, double y, double width, double height, double startAngle, double sweepAngle)
        {
            throw new NotImplementedException();
        }
    }
}
